// ExamClientDlg.h : header file
//

#pragma once
#include "afxcmn.h"
#include "afxwin.h"

#include <vector>
#include "ClientSystem/ClientSystem.h"
using namespace ExamSystem;
using namespace ExamSystem::Client;

#include "Poco\SharedPtr.h"
#include "QuestionWindow.h"


// CExamClientDlg dialog
class CExamClientDlg : public CDialog
{
// Construction
public:
    CExamClientDlg(CWnd* pParent = NULL);    // standard constructor
    ~CExamClientDlg(void);    // standard constructor

// Dialog Data
    enum { IDD = IDD_EXAMCLIENT_DIALOG };

    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support


// Implementation
protected:
    HICON m_hIcon;
    CTreeCtrl m_treeQuestions;
    CStatic m_theQuestionWindow;

    std::vector<int> m_questions[QuestionTypeCount];
    std::vector<bool> m_questionAnswered[QuestionTypeCount];
    std::vector<Poco::SharedPtr<CQuestionWindow> > m_questionWindows[QuestionTypeCount];
    CQuestionWindow *m_presentQuestionWindow;

    HTREEITEM m_questionTypeItems[QuestionTypeCount];
    HTREEITEM m_rootItem;
    CScrollBar m_questionScroll;

    CEdit m_editRestTime;
    CStatic m_staticMessage;

protected:
    void InitializeQuestions(void);
    void InitializeTreeView(void);
    void InitializeQuestionWindows(void);

    void SaveAndHideQuestionWindow(void);
    void ShowAnswerStatus(void);
    void ShowQuestionWindow(int type, int idx);
    Poco::SharedPtr<CQuestionWindow> CreateQuestionWindow(int type, int idx);

    void OnExamStopped(const void *, int &);
    void OnExamMessage(const void *, std::string &msg);
    void OnExamAlert(const void *, std::string &msg);

    // Generated message map functions
    virtual BOOL OnInitDialog();
    afx_msg void OnPaint();
    afx_msg HCURSOR OnQueryDragIcon();
    DECLARE_MESSAGE_MAP()

    virtual void OnOK();
    virtual void OnCancel();
public:
    afx_msg void OnBnClickedOk();
    afx_msg void OnTvnSelchangedQuestionSelection(NMHDR *pNMHDR, LRESULT *pResult);
    afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
    afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
    virtual BOOL PreTranslateMessage(MSG* pMsg);

    void OnQuestionWindowSizeReset(void);
    void QuestionAnswered(QuestionType type, int id);
    afx_msg void OnTimer(UINT_PTR nIDEvent);
    afx_msg void OnDestroy();
};
